package com.leetcode.tree.traversal;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dennis Li
 * @date 2020/7/18 18:48
 */
public class NTreePostorder_590 {

    static class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    List<Integer> ans = new ArrayList<>();

    public List<Integer> postorder(Node root) {
        postOrder(root);
        return ans;
    }

    public void postOrder(Node root) {
        if (root == null) return;
        for (int i = 0; i < root.children.size(); i++) postorder(root.children.get(i));
        ans.add(root.val);
    }

}
